using SS;
using SS.core;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
using TVSBH.func;
namespace TVSGPP.func
{
	public class frmAddSuppend : Form
	{
		private Func objFunc = new Func();
		private string strConnection = "";
		public string ID = "0";
		public string packet = "";
		public string currWhID = "";
		public string userName = "";
		private IContainer components = null;
		private Label label1;
		private TextBox txtproductName;
		private TextBox txtDocumentRefer;
		private Label label6;
		private TextBox txtLocationSampling;
		private Label label7;
		private TextBox txtProcessType;
		private Label label8;
		private Button btnClose;
		private Button btnSave;
		private TextBox txtBalacerNumber;
		private Label label21;
		private ComboBox cbbNational;
		private Label label18;
		private ComboBox cbbPacket;
		private Label label14;
		private TextBox txtProductUnit;
		private Label label10;
		private DateTimePicker dptProductExpiryDate;
		private Label label2;
		private Button btnSelect;
		public frmAddSuppend()
		{
			Program.strConnectionString = this.objFunc.strConnectionString;
			this.InitializeComponent();
		}
		private void btnSave_Click(object sender, EventArgs e)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("ActionOnTabListSuppend", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("Pid", SqlDbType.Int);
				sqlCommand.Parameters.Add("productName", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("Packet", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("ProductExpiryDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("NationalID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("LocationSampling", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("BalacerNumber", SqlDbType.Float);
				sqlCommand.Parameters.Add("ProcessType", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("DocumentRefer", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters["Pid"].Value = int.Parse(this.ID);
				sqlCommand.Parameters["productName"].Value = this.txtproductName.Text;
				sqlCommand.Parameters["Packet"].Value = this.cbbPacket.Text;
				sqlCommand.Parameters["ProductExpiryDate"].Value = this.dptProductExpiryDate.Value;
				try
				{
					sqlCommand.Parameters["NationalID"].Value = this.cbbNational.SelectedValue.ToString();
				}
				catch
				{
					sqlCommand.Parameters["NationalID"].Value = "";
				}
				sqlCommand.Parameters["LocationSampling"].Value = this.txtLocationSampling.Text;
				if (this.txtBalacerNumber.Text.Trim() != "")
				{
					try
					{
						sqlCommand.Parameters["BalacerNumber"].Value = float.Parse(this.txtBalacerNumber.Text);
					}
					catch
					{
						sqlCommand.Parameters["BalacerNumber"].Value = 0;
					}
				}
				sqlCommand.Parameters["ProcessType"].Value = this.txtProcessType.Text;
				sqlCommand.Parameters["DocumentRefer"].Value = this.txtDocumentRefer.Text;
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
				MessageBox.Show("Thông tin đã được lưu vào cở sở dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				this.txtproductName.Text = "";
				this.txtProductUnit.Text = "";
				this.txtLocationSampling.Text = "";
				this.txtBalacerNumber.Text = "0";
				this.txtDocumentRefer.Text = "";
				this.txtProcessType.Text = "";
				this.dptProductExpiryDate.Value = DateTime.Now;
				this.cbbNational.SelectedIndex = 0;
				this.cbbPacket.DataSource = null;
				this.txtproductName.Focus();
			}
			catch
			{
			}
		}
		private void frmAddSideEffects_Load(object sender, EventArgs e)
		{
			this.objFunc.LoadComboBox("SELECT * FROM [TabNational] ORDER BY [Name]", this.cbbNational, "ID", "Name");
			this.currWhID = this.objFunc.getWarehouse(this.userName);
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmAddSideEffects_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
			else
			{
				if (e.KeyCode == Keys.F6)
				{
					this.btnSave.PerformClick();
				}
			}
		}
		private void btnSelect_Click(object sender, EventArgs e)
		{
			products products = new products();
			frmSelectProduct frmSelectProduct = new frmSelectProduct();
			frmSelectProduct.StartPosition = FormStartPosition.CenterScreen;
			frmSelectProduct.MinimumSize = new Size(515, 364);
			frmSelectProduct.FormBorderStyle = FormBorderStyle.FixedToolWindow;
			frmSelectProduct.isInput = true;
			frmSelectProduct.ShowDialog();
			if (frmSelectProduct.productID != "")
			{
				this.ID = frmSelectProduct.productID;
				this.txtproductName.Text = frmSelectProduct.productName;
				this.txtProductUnit.Text = frmSelectProduct.unitName;
				try
				{
					if (this.cbbPacket.Items.Count > 0)
					{
						this.cbbNational.SelectedValue = products.getNationalID(this.ID, this.cbbPacket.SelectedValue.ToString()).ToString();
					}
				}
				catch
				{
				}
			}
		}
		private void cbbPacket_SelectedIndexChanged(object sender, EventArgs e)
		{
			try
			{
				products products = new products();
				this.txtBalacerNumber.Text = products.balancerOfPack(this.ID, this.cbbPacket.SelectedValue.ToString(), this.currWhID).ToString();
			}
			catch
			{
				this.txtBalacerNumber.Text = "0";
			}
		}
		private void txtproductName_TextChanged(object sender, EventArgs e)
		{
			this.cbbPacket.DataSource = null;
			this.objFunc.LoadComboBoxPacket("SELECT DISTINCT [Packet], productName FROM [TabDetailBill] WHERE [Pid] = " + this.ID, this.cbbPacket, "Packet", "Packet");
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmAddSuppend));
			this.label1 = new Label();
			this.txtproductName = new TextBox();
			this.txtDocumentRefer = new TextBox();
			this.label6 = new Label();
			this.txtLocationSampling = new TextBox();
			this.label7 = new Label();
			this.txtProcessType = new TextBox();
			this.label8 = new Label();
			this.btnClose = new Button();
			this.btnSave = new Button();
			this.txtBalacerNumber = new TextBox();
			this.label21 = new Label();
			this.cbbNational = new ComboBox();
			this.label18 = new Label();
			this.cbbPacket = new ComboBox();
			this.label14 = new Label();
			this.txtProductUnit = new TextBox();
			this.label10 = new Label();
			this.dptProductExpiryDate = new DateTimePicker();
			this.label2 = new Label();
			this.btnSelect = new Button();
			base.SuspendLayout();
			this.label1.AutoSize = true;
			this.label1.Location = new Point(21, 17);
			this.label1.Name = "label1";
			this.label1.Size = new Size(67, 15);
			this.label1.TabIndex = 0;
			this.label1.Text = "Tên thuốc :";
			this.txtproductName.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtproductName.Location = new Point(91, 14);
			this.txtproductName.Name = "txtproductName";
			this.txtproductName.Size = new Size(386, 22);
			this.txtproductName.TabIndex = 1;
			this.txtproductName.TextChanged += new EventHandler(this.txtproductName_TextChanged);
			this.txtDocumentRefer.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtDocumentRefer.Location = new Point(91, 129);
			this.txtDocumentRefer.Name = "txtDocumentRefer";
			this.txtDocumentRefer.Size = new Size(386, 22);
			this.txtDocumentRefer.TabIndex = 9;
			this.label6.AutoSize = true;
			this.label6.Location = new Point(23, 132);
			this.label6.Name = "label6";
			this.label6.Size = new Size(65, 15);
			this.label6.TabIndex = 10;
			this.label6.Text = "Công văn :";
			this.txtLocationSampling.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtLocationSampling.Location = new Point(91, 100);
			this.txtLocationSampling.Name = "txtLocationSampling";
			this.txtLocationSampling.Size = new Size(386, 22);
			this.txtLocationSampling.TabIndex = 8;
			this.label7.AutoSize = true;
			this.label7.Location = new Point(9, 103);
			this.label7.Name = "label7";
			this.label7.Size = new Size(79, 15);
			this.label7.TabIndex = 12;
			this.label7.Text = "Nơi lấy mẫu :";
			this.txtProcessType.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtProcessType.Location = new Point(91, 158);
			this.txtProcessType.Name = "txtProcessType";
			this.txtProcessType.Size = new Size(386, 22);
			this.txtProcessType.TabIndex = 10;
			this.label8.AutoSize = true;
			this.label8.Location = new Point(9, 161);
			this.label8.Name = "label8";
			this.label8.Size = new Size(79, 15);
			this.label8.TabIndex = 14;
			this.label8.Text = "Hưởng xử lý :";
			this.btnClose.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new Point(386, 190);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(91, 26);
			this.btnClose.TabIndex = 12;
			this.btnClose.Text = "Thoát [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.btnSave.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnSave.FlatStyle = FlatStyle.Flat;
			this.btnSave.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnSave.Location = new Point(256, 190);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new Size(126, 26);
			this.btnSave.TabIndex = 11;
			this.btnSave.Text = "Lưu thông tin [ F6 ]";
			this.btnSave.UseVisualStyleBackColor = true;
			this.btnSave.Click += new EventHandler(this.btnSave_Click);
			this.txtBalacerNumber.BackColor = Color.White;
			this.txtBalacerNumber.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtBalacerNumber.Location = new Point(236, 72);
			this.txtBalacerNumber.Name = "txtBalacerNumber";
			this.txtBalacerNumber.ReadOnly = true;
			this.txtBalacerNumber.Size = new Size(241, 22);
			this.txtBalacerNumber.TabIndex = 7;
			this.label21.AutoSize = true;
			this.label21.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label21.ForeColor = Color.Black;
			this.label21.Location = new Point(176, 76);
			this.label21.Name = "label21";
			this.label21.Size = new Size(57, 15);
			this.label21.TabIndex = 66;
			this.label21.Text = "Tồn kho :";
			this.cbbNational.BackColor = Color.White;
			this.cbbNational.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbbNational.FlatStyle = FlatStyle.Flat;
			this.cbbNational.FormattingEnabled = true;
			this.cbbNational.Items.AddRange(new object[]
			{
				"      0%",
				"      5%",
				"    10%"
			});
			this.cbbNational.Location = new Point(236, 42);
			this.cbbNational.Name = "cbbNational";
			this.cbbNational.Size = new Size(96, 23);
			this.cbbNational.TabIndex = 4;
			this.label18.AutoSize = true;
			this.label18.Location = new Point(180, 46);
			this.label18.Name = "label18";
			this.label18.Size = new Size(53, 15);
			this.label18.TabIndex = 65;
			this.label18.Text = "Xuất xứ :";
			this.cbbPacket.BackColor = Color.White;
			this.cbbPacket.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbbPacket.FlatStyle = FlatStyle.Flat;
			this.cbbPacket.FormattingEnabled = true;
			this.cbbPacket.Location = new Point(381, 42);
			this.cbbPacket.Name = "cbbPacket";
			this.cbbPacket.Size = new Size(96, 23);
			this.cbbPacket.TabIndex = 6;
			this.cbbPacket.SelectedIndexChanged += new EventHandler(this.cbbPacket_SelectedIndexChanged);
			this.label14.AutoSize = true;
			this.label14.Location = new Point(337, 46);
			this.label14.Name = "label14";
			this.label14.Size = new Size(41, 15);
			this.label14.TabIndex = 64;
			this.label14.Text = "Số lô :";
			this.txtProductUnit.BackColor = Color.White;
			this.txtProductUnit.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtProductUnit.Location = new Point(91, 43);
			this.txtProductUnit.Name = "txtProductUnit";
			this.txtProductUnit.ReadOnly = true;
			this.txtProductUnit.Size = new Size(84, 22);
			this.txtProductUnit.TabIndex = 3;
			this.label10.AutoSize = true;
			this.label10.Location = new Point(17, 46);
			this.label10.Name = "label10";
			this.label10.Size = new Size(71, 15);
			this.label10.TabIndex = 68;
			this.label10.Text = "Đơn vị tính :";
			this.dptProductExpiryDate.CalendarForeColor = Color.Red;
			this.dptProductExpiryDate.CustomFormat = "dd/MM/yyyy";
			this.dptProductExpiryDate.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.dptProductExpiryDate.Format = DateTimePickerFormat.Custom;
			this.dptProductExpiryDate.Location = new Point(91, 72);
			this.dptProductExpiryDate.Name = "dptProductExpiryDate";
			this.dptProductExpiryDate.Size = new Size(84, 22);
			this.dptProductExpiryDate.TabIndex = 5;
			this.label2.AutoSize = true;
			this.label2.Location = new Point(3, 75);
			this.label2.Name = "label2";
			this.label2.Size = new Size(85, 15);
			this.label2.TabIndex = 70;
			this.label2.Text = "Hạn sử dụng :";
			this.btnSelect.BackColor = Color.White;
			this.btnSelect.FlatAppearance.BorderColor = Color.Cyan;
			this.btnSelect.FlatAppearance.BorderSize = 0;
			this.btnSelect.FlatStyle = FlatStyle.Flat;
//			this.btnSelect.Image = (Image)componentResourceManager.GetObject("btnSelect.Image");
			this.btnSelect.Location = new Point(452, 16);
			this.btnSelect.Name = "btnSelect";
			this.btnSelect.Size = new Size(22, 16);
			this.btnSelect.TabIndex = 72;
			this.btnSelect.UseVisualStyleBackColor = false;
			this.btnSelect.Click += new EventHandler(this.btnSelect_Click);
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = Color.White;
			base.ClientSize = new Size(484, 223);
			base.Controls.Add(this.btnSelect);
			base.Controls.Add(this.label2);
			base.Controls.Add(this.dptProductExpiryDate);
			base.Controls.Add(this.txtProductUnit);
			base.Controls.Add(this.label10);
			base.Controls.Add(this.txtBalacerNumber);
			base.Controls.Add(this.label21);
			base.Controls.Add(this.cbbNational);
			base.Controls.Add(this.label18);
			base.Controls.Add(this.cbbPacket);
			base.Controls.Add(this.label14);
			base.Controls.Add(this.btnSave);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.txtProcessType);
			base.Controls.Add(this.label8);
			base.Controls.Add(this.txtLocationSampling);
			base.Controls.Add(this.label7);
			base.Controls.Add(this.txtDocumentRefer);
			base.Controls.Add(this.label6);
			base.Controls.Add(this.txtproductName);
			base.Controls.Add(this.label1);
			this.Cursor = Cursors.Hand;
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			this.MaximumSize = new Size(500, 257);
			this.MinimumSize = new Size(500, 257);
			base.Name = "frmAddSuppend";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = ".: Thuốc ngừng lưu hành";
			base.Load += new EventHandler(this.frmAddSideEffects_Load);
			base.KeyDown += new KeyEventHandler(this.frmAddSideEffects_KeyDown);
			base.ResumeLayout(false);
			base.PerformLayout();
		}
	}
}
